#include <iostream>
#include <list>

using namespace std;

void test1()
{
	int arr[] = { 0,1,2,3,4,5,6,7,8,9 };
	int n = sizeof(arr) / sizeof(arr[0]);

	list<int> lt(arr, arr + n);
	list<int>::iterator pos = find(lt.begin(), lt.end(), 5);
	reverse(lt.begin(), pos); // [ left, right )
	reverse(pos, lt.end());
	list<int>::const_reverse_iterator crit = lt.crbegin();
	while (crit != lt.crend())
	{
		cout << *crit << " ";
		++crit;
	}
	cout << endl;
}


template<typename T>
void removeDuplicates(list<T>& alist)
{
	T curValue;
	list<T>::iterator cur = alist.begin();
	while (cur != alist.end())
	{
		curValue = *cur;
		list<T>::iterator p = ++cur;
		while (p != alist.end())
		{
			if (*p == curValue)
			{
				//p = alist.erase(p);
				cur == p ? cur = p = alist.erase(p) : p = alist.erase(p);
			}
			else
			{
				p++;
			}
		}
	}
}



void test2()
{
	list<int> lt;
	lt.push_back(1);
	lt.push_back(1);
	lt.push_back(2);
	lt.push_back(3);
	lt.push_back(4);
	lt.push_back(5);
	lt.push_back(1);
	lt.push_back(2);
	lt.push_back(1);
	lt.push_back(1);
	lt.push_back(3);

	for (auto e : lt)
	{
		cout << e << " ";
	}
	cout << endl;

	removeDuplicates(lt);
	for (auto e : lt)
	{
		cout << e << " ";
	}
	cout << endl;
}

int main()
{
	test2();

	return 0;
}